package replica;

import common.CommonTools;
import common.Marshall;
import common.ReplicaInfo;
import common.UDPTools_1;

public class ReplicaServer {

	public static void main(String[] args) {
		
		//-------------------------------------------------------------------------------
		String role = args[0];
		Replica replica = new Replica(role);
		UDPTools_1 uDPTools_1 = new UDPTools_1(); 
		
		CommonTools.writeLog(
				role,
				role,
				"start ReplicaServer args[0]:" + args[0] +" args[1]:"+args[1] +" args[2]:"+args[2]
						, "replica");
		
		// replication registration 
		//ReplicaInfo replicaInfo = new ReplicaInfo(Integer.parseInt(args[1]),Boolean.parseBoolean(args[2]),0,null);
		
		String requestMessage = null;
		requestMessage = Marshall.putTag(requestMessage, "Method", "registration");
		requestMessage = Marshall.putTag(requestMessage, "ReplicaId", args[1] );
		requestMessage = Marshall.putTag(requestMessage, "ActiveStatus", args[2]);
		
		String resultTmp = uDPTools_1.sendReceiveUDP( Integer.parseInt(CommonTools.getproperty("replica.properties","UDPPort_" + "replica_manager")),
							CommonTools.getproperty("replica.properties", "serverName_" + "replica_manager"), 
							"replica_manager", role  , requestMessage);
		
		CommonTools.writeLog(
				role,
				role,
				"The replica:" + args[0] +" registration status is:" + resultTmp
						, "replica");
		
		replica.receiveReplyUDP(Integer.parseInt(CommonTools.getproperty("replica.properties","UDPPort_" + role)),
								CommonTools.getproperty("replica.properties", "serverName_" + role));
		
	}

}
